import React, { Component } from 'react'
import { NavLink } from 'react-router-dom';

export default class ComC extends Component {
  constructor() {
    super();
    this.state = {
      msg: '我是子组件'
    }
  }
  changPage(url) {
    // 可以添加逻辑代码
    this.props.history.push(url);
  }
  render(props) {
    return (
      <div>
        <mark>{this.state.msg}</mark>
        {/* 子组件通过this.props接受父组件的数据 */}
        <h1>{this.props.info}</h1>
        <h1>{JSON.stringify(this.props)}</h1>
        {/* 子组件触发父组件的函数，并在参数的位置传入数据，传给父组件 */}
        <button onClick={(e)=>this.props.fn(this.state.msg,e)}>子传父</button>
        <hr />
        <NavLink to="/" activeClassName="active">首页</NavLink><br />
        <NavLink to="/coma" activeClassName="active">coma</NavLink><br />
        <NavLink to="/comb" activeClassName="active">comb</NavLink><br />
        <NavLink to="/comc" activeClassName="active">comc</NavLink><br /> 
        <hr />
        <button onClick={()=>this.changPage('/')}>首页</button>
        <button onClick={()=>this.changPage('/coma')}>coma</button>
      </div>
    )
  }
}
